package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo4 {
    public static void main(String[] args) {
        try (
             Connection connection = DBUtil.getConnection();
        ){
            Statement statement = connection.createStatement();
            String sql = "SELECT s.name sname,s.age sage,s.gender sgender,c.name cname,t.name tname "+
                         "FROM student s "+
                         "JOIN class c ON s.class_id=c.id "+
                         "JOIN teacher t ON c.teacher_id=t.id "+
                         "WHERE c.name='1年级1班' ";
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                String sname = rs.getString("sname");
                int sage = rs.getInt("sage");
                String sgender = rs.getString("sgender");
                String cname = rs.getString("cname");
                String tname = rs.getString("tname");
                System.out.println(sname+","+sage+","+sgender+","+cname+","+tname);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
